/**
 * 验证配置
 */
import axios from "axios"
export default (config:any)=>{
    console.log(config)
    return new Promise(async ress=>{
        let mun = [];
        let type = async (e:any)=>{
            switch (e.type){
                case "html":{
                    // 获取数据，正则匹配
                    let html = (await axios.get(e.url || config.url)).data;
                    // 匹配
                    html = html.match(new RegExp(e.regular.choice,"g"))[e.regular.subscript || 0].replace(new RegExp(e.regular.purify,"g"));
                    mun.push(html)
                }
                case "json":{
                    // 获取数据
                    let data = (await axios.get(e.url || config.url)).data;
                    e.json.split(".").filter((a:any)=>a).forEach((key:any) => {
                        data = data[key]
                    });
                    mun.push(data)
                }
            }
        }

        // 遍历系统
        for(let e in config.system){
            e = config.system[e];
            if(e.type){ 
                await type(e);
            }else{
                // 遍历版本
                Object.keys(e).forEach(async a=>{
                    await type(e[a]);
                })
            }
        }
        ress(mun)
    })
}